<template>
	<view>
		<text>测试页面</text>
		<text>count:{{count}}</text>
		<button @click="increment">++</button>
		<input type="text" v-model="count">
		<my-item info="内容">子组件</my-item>
		<navigator url="../index/index">跳转首页</navigator>
		<button @click="forward">跳转首页</button>
		<button @click="handleHots">获取热映数据</button>
		<button @click="handleLocation">获取位置</button>
		<button @click="handleChoose">选取位置</button>
		<button @click="handleOpenMap">地图</button>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted,
		computed
	} from 'vue';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		getHots
	} from '../../services/film.js';
	const count = ref(0);

	function increment() {
		count.value++;
	}

	function forward() {
		uni.navigateTo({
			url: "/pages/index/index"
		})
	}
	async function handleHots() {
		let data = await getHots();
		console.log("data", data);
	}

	function handleLocation() {
		console.log("location");
		uni.getLocation({
			success: function(res) {
				console.log('address',res);
				console.log('当前位置的经度：' + res.longitude);
				console.log('当前位置的纬度：' + res.latitude);
				uni.openLocation({
							latitude: res.latitude,
							longitude: res.longitude,
							success: function () {
								console.log('success');
							}
						});
			},
			fail(res){
				console.log('fail:',res);
			}
		})
	}
	function handleChoose(){
		uni.chooseLocation({
			success(res){
				console.log('choose',res);
			},
			fail(res){
				console.log('fail',res);
			}
		})
	}
	function handleOpenMap(){
		uni.redirectTo({
			url:"../map-page/map-page"
		})
	}
	onLoad((options) => {
		if(options.item){
			console.log(JSON.parse(decodeURIComponent(options.item)));
		}
	});
	onMounted(() => {
		console.log("mounted");
	});
</script>

<style>

</style>
